package com.ruoyi.recommend.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.recommend.domain.GoodsRecommend;
import com.ruoyi.recommend.service.IGoodsRecommendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品推荐Controller
 * 
 * @author ruoyi
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/ruoyi/recommend")
public class GoodsRecommendController extends BaseController
{
    @Autowired
    private IGoodsRecommendService goodsRecommendService;

    /**
     * 查询商品推荐列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:recommend:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsRecommend goodsRecommend)
    {
        startPage();
        List<GoodsRecommend> list = goodsRecommendService.selectGoodsRecommendList(goodsRecommend);
        return getDataTable(list);
    }

    /**
     * 导出商品推荐列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:recommend:export')")
    @Log(title = "商品推荐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsRecommend goodsRecommend)
    {
        List<GoodsRecommend> list = goodsRecommendService.selectGoodsRecommendList(goodsRecommend);
        ExcelUtil<GoodsRecommend> util = new ExcelUtil<GoodsRecommend>(GoodsRecommend.class);
        util.exportExcel(response, list, "商品推荐数据");
    }

    /**
     * 获取商品推荐详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:recommend:query')")
    @GetMapping(value = "/{recommendId}")
    public AjaxResult getInfo(@PathVariable("recommendId") Long recommendId)
    {
        return success(goodsRecommendService.selectGoodsRecommendByRecommendId(recommendId));
    }

    /**
     * 新增商品推荐
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:recommend:add')")
    @Log(title = "商品推荐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsRecommend goodsRecommend)
    {
        return toAjax(goodsRecommendService.insertGoodsRecommend(goodsRecommend));
    }

    /**
     * 修改商品推荐
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:recommend:edit')")
    @Log(title = "商品推荐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsRecommend goodsRecommend)
    {
        return toAjax(goodsRecommendService.updateGoodsRecommend(goodsRecommend));
    }

    /**
     * 删除商品推荐
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:recommend:remove')")
    @Log(title = "商品推荐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recommendIds}")
    public AjaxResult remove(@PathVariable Long[] recommendIds)
    {
        return toAjax(goodsRecommendService.deleteGoodsRecommendByRecommendIds(recommendIds));
    }
}
